/* 
 * File:   repository.cpp
 * Author: jolo
 * 
 * Created on: 10. Oktober 2011, 17:42
 * Lincense: New BSD License (The BSD 2-Clause License)
 */

#include "repository.hpp"

#include <boost/foreach.hpp>

#include "project.hpp"
#include "chemical_element.hpp"
#include "core/application.hpp"

namespace model
{

    repository::repository(const string& path)
    : entity(),
    path_(path)
    {
    }

    repository::~repository()
    {
    }

    void repository::print_on(std::ostream& s)
    {
        s << to_string();
    }

    const string repository::to_string() const
    {
        stringstream s;
        s << object_name() << ": Path: '" << path() << "': " << entity::to_string();
        return s.str();
    }

    void repository::bootstrap_data()
    {
        bootstrap_elements();
        bootstrap_project();
    }

    void repository::bootstrap_elements()
    {
        create_chemical_element("H", "Hydrogen", "1", "1", 1.0, 1.00794, "");
        create_chemical_element("He", "Helium", "1", "8", 4.00260, 2, "");
    }

    void repository::bootstrap_project()
    {
        create_project("A Project");
    }

    project_ptr repository::create_project(const string& name)
    {
        project_ptr p(new project(name, "", this));
        projects_.push_back(p);
        return p;
    }

    chemical_element_ptr repository::create_chemical_element(const string& symbol,
                                                             const string& name,
                                                             const string& group,
                                                             const string& period,
                                                             const double atomic_weight,
                                                             const int number,
                                                             const string& description)
    {

        chemical_element_ptr p(new chemical_element(symbol, name, description, group, period,
                                                    atomic_weight, number, this));
        chemical_elements_.push_back(p);
        return p;
    }
    
    const string repository::short_label() const {
        return path();
    }
    
    const string repository::object_name() const {
        return "Repository";
    }
}
